#include <iostream>
#include <vector>
#include <cstdlib>
#include <string>
using namespace std;

typedef struct {
	int weight;
	string colors;
} person;

int main() {
	vector<person> queue;
	int len;
	cin >> len;
	person temp;
	for (int i = 0; i < len; i++) {
		cin >> temp.weight >> temp.colors;
		queue.push_back(temp);
	}

	for (int i = queue.size() - 1; i > 0; i--)
		for (int j = 0; j < i; j++) {
			if (queue[j].weight > queue[j + 1].weight) {
				temp = queue[j];
				queue[j] = queue[j + 1];
				queue[j + 1] = temp;
			}
		}
	for (auto i : queue)
		cout << i.colors << endl;
}